package com.example.demo;

import com.example.demo.component.UserComponent;
import com.example.demo.config.BeanConfig;
import com.example.demo.config.UserConfig;
import com.example.demo.controller.UController;
import com.example.demo.controller.UserController;
import com.example.demo.model.UserInfo;
import com.example.demo.repository.UserRepository;
import com.example.demo.service.UserService;
import org.apache.catalina.core.ApplicationContext;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;

import java.beans.Introspector;

@SpringBootApplication
public class SpringIocApplication {

	public static void main(String[] args) {
		ConfigurableApplicationContext context = SpringApplication.run(SpringIocApplication.class, args);

//		// @Controller
//		UserController bean = context.getBean(UserController.class);
//		bean.sayHi();

//		// @Service
//		// 根据类型获取 bean
//		UserService bean = context.getBean(UserService.class);
//		System.out.println(bean);
//		// 根据名称获取 bean
//		Object userService = context.getBean("userService");
//		System.out.println(userService);
//		// 根据类型和名称获取 bean
//		UserService userService1 = context.getBean(UserService.class, "userService");
//		System.out.println(userService1);
//		userService1.sayHi();

//		// @Repository
//		UserRepository userRepository = (UserRepository)context.getBean("userRepository");
//		userRepository.sayHi();

//		// @Component
//		UserComponent bean = context.getBean(UserComponent.class);
//		bean.sayHi();

//		// @Configuration
//		UserConfig userConfig = context.getBean(UserConfig.class, "userConfig");
//		userConfig.sayHi();

//		// 首字母和第二个字母大写的情况
//		UController bean = context.getBean(UController.class);
//		bean.sayHi();
//		UController uController = (UController)context.getBean("UController");
//		uController.sayHi();
//		UController uController = context.getBean(UController.class, "UController");
//		uController.sayHi();

//		System.out.println(Introspector.decapitalize("HelloController"));
//		System.out.println(Introspector.decapitalize("UController"));

//		UserInfo bean = (UserInfo) context.getBean("userInfo");
//		System.out.println(bean);
	}

}
